﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace ADO.NetDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=.;Initial Catalog=School;Integrated Security=True;Pooling=False";

            SqlCommand cmd = new SqlCommand();
            //cmd.CommandText = "delete from student where rollno=1";
            //cmd.CommandText = "update student set Name='Barun Sen' where rollno=2";
            //cmd.CommandText = "insert into student(RollNo,Name,phonE) values(3,'Rabin','566443214')";
            cmd.CommandText = "select * from student";
            cmd.Connection = conn;


            //conn.Open();
            //int r = cmd.ExecuteNonQuery(); // for insert update delete
            //conn.Close();

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader(); //for select
            while (reader.Read())
            {
                Console.WriteLine("Roll  = " + reader["RollNo"]);
                Console.WriteLine("Name  = " + reader["Name"]);
                Console.WriteLine("Phone = " + reader["Phone"]);
                Console.WriteLine("Reg. Date  = " + reader["RegDate"]);
            }
            conn.Close();
            Console.Read();
        }
    }
}
